package hehe.log.base;

import hehe.log.collect.SyncCollect;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/**
 * 日志收集器基类
 *<B>说明：</B>
 *<pre>
 * 略
 *</pre>
 *<B>示例：</B>
 *<pre>
 *  略
 *</pre>
 *<B>日志：</B>
 *<pre>
 *  略
 *</pre>
 *<B>注意事项：</B>
 *<pre>
 *  略
 *</pre>
 */
abstract public class Logger
{

    /**
     * 日志目标
     *<B>说明：</B>
     *<pre>
     * 属性详细描述
     *</pre>
     */
    protected List<Target> targets = new ArrayList<>();

    /**
     * 收集器
     *<B>说明：</B>
     *<pre>
     *  略
     *</pre>
     */
    protected Collect collect;

    public void setCollect(Collect collect)
    {
        this.collect = collect;
        this.collect.setLogger(this);
    }

    public void addTarget(Target target)
    {
        this.targets.add(target);
    }

    public List<Target> getTargets()
    {
        return this.targets;
    }

    //  调试日志
    public void debug(Object msg)
    {
        this.log(msg,Level.DEBUG_LEVEL,null);
    }

    public void debug(Object msg, Throwable t)
    {
        this.log(msg,Level.DEBUG_LEVEL,t);
    }

    // 错误日志
    public void error(Object msg)
    {
        this.log(msg,Level.ERROR_LEVEL,null);
    }

    public void error(Object msg, Throwable t)
    {
        this.log(msg,Level.ERROR_LEVEL,t);
    }

    // 警告日志
    public void warn(Object msg)
    {
        this.log(msg,Level.WARN_LEVEL, null);
    }

    public void warn(Object msg, Throwable t)
    {
        this.log(msg,Level.WARN_LEVEL, t);
    }

    // 业务日志
    public void info(Object msg)
    {
        this.log(msg,Level.INFO_LEVEL, null);
    }

    public void info(Object msg, Throwable t)
    {
        this.log(msg,Level.INFO_LEVEL, t);
    }

    // 致命错误日志
    public void fatal(Object msg)
    {
        this.log(msg,Level.FATAL_LEVEL, null);
    }

    public void fatal(Object msg, Throwable t)
    {
        this.log(msg,Level.FATAL_LEVEL, t);
    }

    // 追踪日志
    public void trace(Object msg)
    {
        this.log(msg,Level.TRACE_LEVEL, null);
    }

    public void trace(Object msg, Throwable t)
    {
        this.log(msg,Level.TRACE_LEVEL, t);
    }

    /**
     * 日志收集入口
     *<B>说明：</B>
     *<pre>
     * 由子类实现
     *</pre>
     */
    abstract public void log(Object msg,String level,Throwable t);
}
